#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Enemys
@Time    :   2023/03/21 19:11:19
@author  :   Eval
@Version :   1.0
@Describe:   敌人类
'''
from lib.scripts.GC import *
from lib.scripts.AStart_Path import *
from lib.scripts.GameInit import *

class Enemys:
    """
    @param {*}: parent 游戏主窗体
    @param {*}: eData  敌人的数据, 
    """
    def __init__(self,parent,eData:dict,x=0,y=0) -> None:
        import main
        self.parent:main.Run = parent
        self.localPos = [int(y),int(x)]  # 相对于地图的坐标点
        self.scenePos = [int(y)*32 , int(x)*32]
        self.image = GC.GC_GameSurfaceCache.get(eData["type"])

        # 创建一个用于绘制在ui上的 精灵,例如 对话事件,以及怪物事件等..
        self.imageUI = BlockSprite(GC.GC_GameSurfaceCache.get(eData["type"]),eData)
        self.imageUI.h = 32  # 如果有其他尺寸的敌人,在这里修改精灵的高度,否则默认是 32

        # 当前动画帧
        self.animMax = int(eData["animMax"])
        self.animIndex = 0
        self.type = eData["type"]
        self.name = eData.get("name") or "无名"
        self.key = int(eData["key"])
        self.index = int(eData["index"])
        self.canPass = False
        self.describe = eData.get("describe") or "null"
        self.hp = int(eData.get("hp")) or 100
        self.atk = int(eData.get("atk")) or 10
        self.defe = int(eData.get("def")) or 1
        self.money = int(eData.get("money")) or 1
        self.exp = int(eData.get("exp")) or 1
        self.skill = eData.get("skill") or []
        self.speed = eData.get("speed") and int(eData.get("speed")) or 2
        self.w = 32
        self.h = 32

        self.damage = 0  # 敌人会对玩家造成多少伤害,初始为0 , 在渲染怪物手册时根据 战斗公式计算结果显示
        
        # 是否存活
        self.active = True

    def update(self,*args):
        # 已经死亡的敌人就不渲染了
        if not self.active:
            return
        if self.animMax >0 and self.parent.GInit.delay % 20 == 0:
            self.animIndex = (self.animIndex+1) % self.animMax

        self.parent.win.blit(self.image,[self.scenePos[0]+200,self.scenePos[1]],(self.animIndex *self.w,self.h*self.index,self.w,self.h))

    def status(self) -> str:
        """返回怪物属性渲染怪物手册"""
        return f"hp:{self.hp} 攻击力:{self.atk} 防御力:{self.defe}\n\n金币:{self.money} 经验:{self.exp}"

    def __str__(self) -> str:
        return f"姓名:{self.name} ,生命值:{self.hp} ,攻击力:{self.atk} ,防御力:{self.defe},金币:{self.money} ,经验:{self.exp},坐标:{self.localPos}"